(function($){
	
	function displayLightingSubject(){
		$('#subject').toggle();
	};
	
	function collectInfo(){
		
		var hmoRecord = {
			personal: {
				name: $('#txtName').val(),
				email: $('#txtEmail').val(),
				url: $('#txtUrl').val(),
				twitterHandle: $('#txtTwitter').val(),
				facebookHandle: $('#txtFacebook').val()
			},
			hmodevhouse: {
				edition: 12,
				firstTimer:  $("input[name='rdFirstTime']:checked").val() === "yes" ? true : false,
				infoChannel:  $("input[name='rdWayToKnow']:checked").val()
			},
			todaysWork: {
				subject: $('#txtWork').val(),
				lightingTalk: $("input[name='rdLighting']:checked").val() === "yes" ? true : false,
				lightingSubject: $('#txtLightingSubject').val()
			}
		}; 
		
		return addRecord(hmoRecord);
		
	};
	
	function addRecord(record){
		
		if (record === undefined) {
			return false;
		}

		if ($.ajax) {
			
			$.ajax({
				type: "POST",
				url: "couchdb/hmodevhouse",
				contentType: "application/json;",
				data: JSON.stringify(record),
				dataType: "json",
				error: function(error){
					alert("Error");
				},
				success: function(success){
					alert("Gracias por la Info! Disfruta del HmoDevHouse12");
					
					window.location = "list.html";
				}
			});
		}
	};
	
	//On Ready
	$(document).ready(function(){
		$("#saveRegistry").click(collectInfo);
		$('#rdLightingYes').click( function(e){ $('#subject').show(); } );
		$('#rdLightingNo').click(function(e){ $('#subject').hide(); });
		
		$('#subject').hide();
	});
	
})(jQuery);
